class MyPage extends BaseList {
    constructor(orderby, flag, mpsId, $pagesize, $pagination, listUrl, onLineEditUrl, checkBoxName) {
        super(orderby, flag, $pagesize, $pagination, listUrl, onLineEditUrl, checkBoxName);
        this.mpsId = mpsId;
    }
    GetFilter(pageIndex) {
        let item = super.GetFilter(pageIndex);
        item["MpsId"] = this.mpsId;
        return JSON.stringify(this.mpsId);
    }
    FetchAll() {
        this.FetchForPage(1);
    }
    EmptyTableContent() {
        $("#tabData01 tbody").empty();
        $("#tabData02 tbody").empty();
    }
    SetTableContent(result) {
        $("#tabData01 tbody").empty();
        $("#tabData02 tbody").empty();
        let content_01 = '';
        let content_02 = '';
        this.rows = result.length;  // 设置表格中checkbox的数量为表格的行数
        this.numCheckbox = result.length;  // 设置表格中checkbox的数量为表格的行数
        for (let i = 0; i < result.length; i++) {
            content_01 = '<tr _mash_id="' + result[i].linesId + '" _productId="' + result[i].productId + '">';
            if (parseInt(this.flag) === 0) { // 单选
                content_01 += '<td style="padding-left:8px; padding-top:0px; vertical-align:baseline;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_check_row" type="radio" onclick="_Instance.OnChoice($(this));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            } else { // 多选
                content_01 += '<td style="padding-left:9px;"><label class="btn" for="R-' + result[i].linesId + '"><input id="R-' + result[i].linesId + '" name="_check_row" type="checkbox" onclick="_Instance.DoCheckRow($(this),$(\'#CheckAll\'));" value="' + result[i].linesId + '"/><i></i><span></span></label></td>';
            }
            content_01 += '<td>' + formatNullData(result[i].customerName) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].styleNo) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].quantity) + '</td>';
            content_01 += '<td>' + formatNullData(result[i].productColour) + '</td>';
            content_01 += '</tr>';

            content_02 += '<tr style="height:24px;">';
            content_02 += '<td>' + formatNullData(result[i].dateOfDelivery) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfColourCards) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfHandSample) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfProductSheet) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfTechnicalDataFinish) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfPieceYardage) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfMaterialRequirement) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfMaterialPrepared) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfChemicalInspection) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfCuttingPrinting) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].dateOfTechnicalDataIssue) + '</td>';
            content_02 += '<td>' + formatNullData(result[i].cmt) + '</td>';    //加工费
            content_02 += '<td style="border-right: none;">' + formatNullData(result[i].description) + '</td>';
            content_02 += '</tr>';

            $("#tabData01 tbody").append(content_01);
            $("#tabData02 tbody").append(content_02);
            content_01 = '';
            content_02 = '';
        }
        setTwoTableRowColor("tabData01", "tabData02");
        this.AdjustDataTableHeight();

        $(window).resize();                     // 防止因为出现滚动条而造成画面显示问题
        $('#loading').hide();
    }
    // 选择后执行的动作
    SetChoiceData($self) {
        // 设置选择结果
        let $tr1 = $self.parent().parent().parent();
        var $tr2 = $("#tabData02 tbody tr").eq($tr1.index());
        //设置选择结果
        return new Array($self.val(),
                $.trim($tr1.find('td').eq(1).text()), // 合同号
                $.trim($tr2.find('td').eq(0).text()), // 贸易方式
                $.trim($tr2.find('td').eq(2).text()));  // 系列号
    }
    OnMultiChoice() {
        var _suitNoOfStyle = '';
        var _customerName = '';
        var _dateOfMaterialPrepared = '';
        var _dateOfCuttingPrinting = '';
        var _dateOfTechnicalDataFinish = '';
        var _dateOfChemicalInspection = '';
        var _arrProductId = [];

        $("#tabData01 tr").each(function (index) {
            let _self = $(this).children("td").eq(0).children("label").eq(0).children("input[type='checkbox'][name='_check_row']").eq(0);

            if (_self.is(":checked") === true) {
                _arrProductId.push($(this).attr("_productId"));                         // 保存产品标识
                _customerName = $.trim($(this).children("td").eq(1).text());            // 客户名
                _suitNoOfStyle += $.trim($(this).children("td").eq(2).text()) + "/";    // 款号

                _dateOfMaterialPrepared = $.trim($("#tabData02 tr").eq(index).children("td").eq(8).text());      // 组料完成日
                _dateOfCuttingPrinting = $.trim($("#tabData02 tr").eq(index).children("td").eq(9).text());       // 裁片印花日
                _dateOfTechnicalDataFinish = $.trim($("#tabData02 tr").eq(index).children("td").eq(4).text());   // 技术资料完成日
                _dateOfChemicalInspection = $.trim($("#tabData02 tr").eq(index).children("td").eq(10).text());   // 化检日
            }
        });
        _suitNoOfStyle = _suitNoOfStyle.substring(0, _suitNoOfStyle.length - 1);      // 规范款号格式，去掉最后一个字符(/)

        // 设置选择结果
        let item = new Array(_customerName, _suitNoOfStyle.toUpperCase(), _dateOfMaterialPrepared, _dateOfCuttingPrinting,
                _arrProductId, _dateOfTechnicalDataFinish, _dateOfChemicalInspection);
        parent.arrChoice.push(item);
        parent.choice_success = true;
        closePopupWnd();
    }
    // 设置行选择后的状态
    SetRowStatus($self) {
        super.AdjustRowStatus($self, ($row, index) => {
            let key = $self.val();
            let item = {};
            $('#tabData02 tbody tr:eq(' + index + ')').addClass("row__selected");
            item["mpsLinesId"] = key;
            this.selectedItemList[key] = item;
        }, ($row, index) => {
            let key = $self.val();
            $('#tabData02 tbody tr:eq(' + index + ')').removeClass("row__selected");
            delete this.selectedItemList[key];
        });
    }
    SortTable(orderBy) {
        this.orderby = orderBy;
        // 得到排序数据
        this.FetchForPage(1);
    }
    ScrollTo() {
        $('#divH2').scrollLeft($('#divD2').scrollLeft());
        $('#divD1').scrollTop($('#divD2').scrollTop());
    }
    AdjustDataTableHeight() {
        var h = $(window).height();
        var _rc = Math.floor((h - 70) / 25);
        var _dh = _rc * 25 + 17;
        var _rowH = this._rows * 25 + 17; // 计算行高
        _dh = (_rowH >= _dh) ? _dh : _rowH;

        $("#divD1").css({"max-height": _dh - 17, height: _dh - 17});
        $("#divD2").css({"max-height": _dh + 1, height: _dh + 1});
    }
}

let _Instance = null;

//-----------------------------------------------------------------------------
// 页面初始化
//-----------------------------------------------------------------------------
function onPageReady() {
    let flag = jQuery.url.param("flag") === undefined ? 0 : jQuery.url.param("flag");
    let mpsId = jQuery.url.param("mpsId") === undefined ? 0 : jQuery.url.param("mpsId");
    _Instance = new MyPage(null, flag, mpsId, null, null,
            "/trade/master_production_schedule/lines/fetchByHeaderKey.html",
            "",
            "_check_row");

    _Instance.OnPageLoad();
}

// 画面大小或者位置移动
function onPageResize() {
    let wLeftList = 651; //左边列表固定宽度
    let w = $(window).width();

    $("#divH2").css({left: 0, width: w - 16 - wLeftList});
    $("#divD2").css({left: -1, width: w - 15 - wLeftList});
}